package com.nowcoder.community;


import org.w3c.dom.Node;

import java.util.*;
import java.util.stream.Collectors;

public class Solution {
    public static void main(String[] args){
        System.out.println("rzzmf\nv\n\tix\n\t\tiklav\n\t\t\ttqse\n\t\t\t\ttppzf\n\t\t\t\t\tzav\n\t\t\t\t\t\tkktei\n\t\t\t\t\t\t\thhmav\n\t\t\t\t\t\t\t\tbzvwf.txt");
        System.out.println(lengthLongestPath("rzzmf\nv\n\tix\n\t\tiklav\n\t\t\ttqse\n\t\t\t\ttppzf\n\t\t\t\t\tzav\n\t\t\t\t\t\tkktei\n\t\t\t\t\t\t\thhmav\n\t\t\t\t\t\t\t\tbzvwf.txt"));
    }
    public static int lengthLongestPath(String input) {
        int maxLength = 0;
        int[] multiLevelLength = new int[1000];
        String[] multiLevelDirs = input.split("\\n");
        System.out.println(Arrays.toString(multiLevelDirs));
        for (String dir : multiLevelDirs){
            int tabCount = countTab(dir);
            int curLength = dir.length() + multiLevelLength[tabCount - 1];
            curLength += tabCount == 1 ? 0 : (2 - tabCount);
            if (curLength > multiLevelLength[tabCount]){
                multiLevelLength[tabCount] = curLength;
            }
            if (dir.contains(".")){
                maxLength = Math.max(maxLength, multiLevelLength[tabCount]);
            }
        }
        return maxLength;
    }

    private static int countTab(String dir){
        int cur = 0, count = 1;
        while (cur < dir.length()){
            if (dir.charAt(cur) == '\t'){
                count++;
                cur ++;
            } else {
                break;
            }
        }
        return count;
    }

}







